<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>编辑站点的信息</title>
    <link rel="stylesheet" href="/js/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/ztree/css/demo.css" type="text/css">
    <link rel="stylesheet" href="/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css">
    <script type="text/javascript" src="/ztree/js/jquery-1.4.4.min.js"></script>
    <script type="text/javascript" src="/ztree/api/apiCss/jquery.ztree.core.js"></script>
    <script src="/js/layui/layui.all.js"></script>
    <script src="/admin/js/token.js"></script>

</head>
<body>
<style type="text/css">

    .ztree li span.button.icon01_ico_docu {
        background: url(js/zTree-zTree_v3-master/zTree_v3/css/zTreeStyle/img/index.png);
        margin-right: 2px;
        background-position: -110px -16px;
        vertical-align: top;
        no-repeat: scroll 0 0 transparent;
        vertical-align: top;
        *vertical-align: middle
    }

    .ztree li span.button.icon01_ico_open, .ztree li span.button.icon01_ico_close {
        background: url(js/zTree-zTree_v3-master/zTree_v3/css/zTreeStyle/img/index.png);
        margin-right: 2px;
        background-position: -110px -16px;
        vertical-align: top;
        no-repeat: scroll 0 0 transparent;
        vertical-align: top;
        *vertical-align: middle
    }

    .formbox {
        height: 1px;
    }

    body {
        background-color: white;
    }

    .layui-form-label {
        width: 100px;
    }

    .layui-input-block {
        margin-left: 130px;
    }
</style>
<div class="layui-row">
    <div class="layui-col-md2  formbox ">
    </div>

    <div class="layui-fluid layui-col-md8 layui-col-sm12 ">
        <div class="layui-card">
            <div class="layui-card-body" style="padding: 15px;" class="layui-row">
                <form class="layui-form" lay-filter="selFilter">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color:red">*</span>站点编号:</label>
                        <div class="layui-input-block">
                            <input name="stationBh" class="layui-input" autocomplete="off"
                                   lay-verify="required|stationName"
                                   id="stationBh" readonly="readonly" style="cursor:no-drop">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color:red">*</span>站点名称:</label>
                        <div class="layui-input-block">
                            <input name="stationName" class="layui-input" autocomplete="off"
                                   lay-verify="required|stationName"
                                   id="stationName">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color:red">*</span>站点类型:</label>
                        <div class="layui-input-block">
                            <select name="stationType" id="stationType" lay-verify="required">
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color:red">*</span>所属用户:</label>
                        <div class="layui-input-block">
                            <input class="layui-input" autocomplete="off" lay-verify="required|suoshuyonghu"
                                   id="admin" name="stationAdminId">
                            <div id="boos"
                                 style="display:none;position: absolute;z-index: 100;">
                                <ul id="treeDemo" class="ztree"
                                    style="height: 160px;background: white;border:1px solid gray;overflow-y: scroll"></ul>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color:red">*</span>地址</label>
                        <div class="layui-input-inline">
                            <input name="stationArea" class="layui-input" style="cursor:no-drop" readonly="readonly"
                                   id="quyu" lay-filter="demo">
                        </div>
                        <div class="layui-input-inline">
                            <select name="stationProvince" id="sheng" lay-verify="required">
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color:red">*</span>详细地址:</label>
                        <div class="layui-input-block">
                            <input name="address" class="layui-input" autocomplete="off"
                                   lay-verify="required|xiangxidizhi"
                                   id="xiangxidizhi">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color:red">*</span>联系电话:</label>
                        <div class="layui-input-block">
                            <input name="stationPhone" class="layui-input" type="tel" autocomplete="off"
                                   lay-verify="required|phone"
                                   id="phone">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label" style="padding: 0px 15px">点播服务器IP:</label>
                        <div class="layui-input-block">
                            <input name="stationLocalServerIp" class="layui-input" autocomplete="off"
                                   id="dianbofuwuqiIp">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">VPN地址:</label>
                        <div class="layui-input-block">
                            <input name="stationVpn" class="layui-input" autocomplete="off" id="VPN">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">点钟宝IP地址:</label>
                        <div class="layui-input-block">
                            <input name="stationDzbIp" class="layui-input" autocomplete="off" id="dianzhongbao">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">锁定提示语:</label>
                        <div class="layui-input-block">
                            <input class="layui-input" autocomplete="off" name="stationLocktip"
                                   id="tishi" type="text">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color:red">*</span>是否开启OSS:</label>
                        <div class="layui-input-block">
                            <select id="stationOss" lay-verify="required" name="stationOss">
                                <option value="开启">开启</option>
                                <option value="关闭">关闭</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color:red">*</span>创建时间:</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-input" id="begin" placeholder="创建时间"
                                   name="stationCreateTime">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color:red">*</span>站点模式:</label>
                        <div class="layui-input-block">
                            <select name="stationModel" id="stationMoshi" lay-verify="required">
                                <option value="买断">买断模式</option>
                                <option value="租赁">租赁模式</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-form-item layui-layout-admin">
                        <div class="layui-input-block">
                            <div class="layui-footer" style="left: 0">
                                <button class="layui-btn" lay-filter="demo1" lay-submit style="margin-left: 37%;">修改
                                </button>
                                <button class="layui-btn layui-icon layui-icon-close" id="back">
                                    取消
                                </button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="layui-col-md2 formbox">

            </div>
        </div>
    </div>
</div>
</body>
<script>
        var form = layui.form
        var laydate = layui.laydate
        var data = layui.data('updatedata')
        var adminid = data.getdata.station_admin_id;
        var phone=layui.data("local_store").token;
        var zTreeObj
        var a = null
        var $ = layui.$;
        var setting = {
            view: {
                dblClickExpand: false,
                showLine: true,
                selectedMulti: false
            },
            data: {
                simpleData: {
                    enable: true,
                    idKey: 'id',
                    pIdKey: 'pid',
                    rootPId: '0'
                }
            },
            callback: {
                onMouseDown: itemMouseDown //单击事件
            }
        }

        function itemMouseDown(event, treeId, treeNode) {
            $('#admin').val(treeNode ? treeNode.name : $('#admin').val())
            adminid = treeNode ? treeNode.id : adminid
        }

        $.ajax({
            type: 'get',
            url: '/admin/selectShujsonById',
            async: true,
            data: {
                token: phone
            },
            success: function (msg) {
                $j = jQuery.noConflict();
                var treeNodes = eval(eval(msg).data);
                zTreeObj = $j.fn.zTree.init($j("#treeDemo"), setting, treeNodes);
                $ = layui.$;
            }
        })
        //根据区域id查省
        $.ajax({
            type: 'get',
            url: '/admin/province/selprovince',
            async: false,
            data: {
                Code: data.getdata.station_area
            },
            success: function (res) {
                $('#sheng').empty()
                for (var i = 0; i < res.data.length; i++) {
                    $('#sheng').append(new Option(res.data[i].provinceName, res.data[i].provinceCode))
                }
                layui.form.render('select')
            }
        })
        //查站点类型
        $.ajax({
            type: 'get',
            url: '/admin/station-type/AllStationType',
            async: false,
            success: function (res) {
                for (var i = 0; i < res.data.length; i++) {
                    $('#stationType').append(new Option(res.data[i].stationTypeName, res.data[i].stationTypeId))
                }
                layui.form.render('select')
            }
        })
        //将详细地址插入
        $.ajax({
            type: 'get',
            url: '/admin/address/selectAddress',
            data: {
                id: data.getdata.address_id
            },
            success: function (res) {
                if (res.code == 200) {
                    $('#xiangxidizhi').val(res.data.detailedAddress)
                }
            }
        })
        $('#stationBh').val(data.getdata.station_bh)
        $('#stationName').val(data.getdata.station_name)
        $('#stationType').val(data.getdata.station_type)
        $('#admin').val(data.getdata.admin_name)
        $('#quyu').val(data.getdata.station_quyu)
        $('#sheng').val(data.getdata.station_province)
        $('#phone').val(data.getdata.station_phone)
        $('#dianbofuwuqiIp').val(data.getdata.station_local_server_ip)
        $('#VPN').val(data.getdata.station_vpn)
        $('#dianzhongbao').val(data.getdata.station_dzb_ip)
        $('#tishi').val(data.getdata.station_locktip)
        $('#stationOss').val(data.getdata.station_oss)
        $('#begin').val(data.getdata.station_create_time)
        $('#stationMoshi').val(data.getdata.station_model)
        form.render('select', 'selFilter')
        //执行一个laydate实例
        laydate.render({
            elem: '#begin', //指定元素
            type: 'datetime'
        })
        //    编辑站点的监听事件
        var addressid = data.getdata.address_id
        var stationid = data.getdata.station_id
        var stationarea = data.getdata.station_area
        var token=layui.data("local_store").token;
        form.on('submit(demo1)', function (data) {
            $.ajax({
                type: 'post',
                url: '/admin/station/editStationMes',
                data: {
                    stationId: stationid,
                    stationName: $('#stationName').val(),
                    stationType: $('#stationType').val(),
                    stationAdminId: $('#admin').val(),
                    stationArea: stationarea,
                    stationProvince: $('#sheng').val(),
                    addressId: addressid,
                    address: $('#xiangxidizhi').val(),
                    stationPhone: $('#phone').val(),
                    stationLocalServerIp: $('#dianbofuwuqiIp').val(),
                    stationVpn: $('#VPN').val(),
                    stationDzbIp: $('#dianzhongbao').val(),
                    stationLocktip: $('#tishi').val(),
                    stationOss: $('#stationOss').val(),
                    stationModel: $('#stationMoshi').val(),
                    stationCreateTime: $('#begin').val(),
                    stationAdminId: adminid,
                    adminidnow:token
                },
                success: function (res) {
                    console.log(res)
                    if (res.code == 200) {
                        layer.msg('修改成功', {
                            icon: 1,
                            time: 1000
                        })
                        setTimeout(function () {
                            var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                            parent.layer.close(index);    //关闭弹出层
                        }, 1000)
                        return
                    }
                    layer.msg(res.data, {
                        icon: 2
                    })
                },
                error: function () {
                    layer.msg('网络原因修改失败', {
                        icon: 2
                    })
                }
            })
            return false
        })
        $(function () {
            $('#admin').click(function (event) {
                event.stopImmediatePropagation();//取消事件冒泡；
                $("#boos").toggle('slow');
            });
            $(document).bind("click", function (e) {
                var target = $(e.target);
                if (target.closest("#admin,#boos").length == 0) {/*.closest()沿 DOM 树向上遍历，直到找到已应用选择器的一个匹配为止，返回包含零个或一个元素的 jQuery 对象。*/
                    $("#boos").fadeOut();
                }
                ;
                e.stopPropagation();
            })
        });

        $('#back').click(function () {
            var index = parent.layer.getFrameIndex(window.name) //获取窗口索引
            parent.layer.close(index)    //关闭弹出层
        })
</script>
</html>
